package com.rabbit.rabbitmqspringboot.listen;


import com.rabbit.rabbitmqspringboot.constant.Constants;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;


@Component
public class RabbitListen {

    // 工作模式
    @RabbitListener(queues = Constants.WORK_QUEUE)
    public void work(Message message){
        System.out.println("worklisten 监听： 收到的信息是 "+ new String(message.getBody()));
    }

    // fanout 发布订阅模式
    @RabbitListener(queues = Constants.FANOUT_QUEUE1)
    public void fanout1(Message message){
        System.out.println("fanout1 监听： 收到的信息是 "+ new String(message.getBody()));
    }
    @RabbitListener(queues = Constants.FANOUT_QUEUE2)
    public void fanout2(Message message){
        System.out.println("fanout2 监听： 收到的信息是 "+ new String(message.getBody()));
    }

    // 路由模式
    @RabbitListener(queues = Constants.DIRECT_QUEUE1)
    public void direct1(Message message){
        System.out.println("direct1 监听： 收到的信息是 "+ new String(message.getBody()));
    }
    @RabbitListener(queues = Constants.DIRECT_QUEUE2)
    public void direct2(Message message){
        System.out.println("direct2 监听： 收到的信息是 "+ new String(message.getBody()));
    }


    // topic 通配符模式
    @RabbitListener(queues = Constants.TOPIC_QUEUE1)
    public void topic1(Message message){
        System.out.println("topic1 监听： 收到的信息是 "+ new String(message.getBody()));
    }
    @RabbitListener(queues = Constants.TOPIC_QUEUE2)
    public void topic2(Message message){
        System.out.println("topic2 监听： 收到的信息是 "+ new String(message.getBody()));
    }
}
